﻿using System;

namespace ConsoleApp3_Bank
{
    public class CreditAccount : Account//继承Account类
    {
        private decimal CreditLimit;//信用额度

        public decimal getCreditLimit//获取信用额度
        {
            get { return CreditLimit; }
        }

        //构造函数
        public CreditAccount(string AccountNum, decimal iBalance, decimal CreditLim)
            : base(AccountNum, iBalance)
        {
            CreditLimit = CreditLim;
        }

        //覆盖取款方法
        public override void Withdraw(decimal amount)
        {
            if (amount > 0 && amount <= getBalance)
            {
                base.Withdraw(amount);
            }
            else if(amount > getBalance && amount <= getBalance + getCreditLimit)
            {
                CreditLimit -= amount - getBalance;
                Console.WriteLine($"本次取款金额为{amount}，信用额度为{CreditLimit}元。");
            }
            else
            {
                Console.WriteLine("信用额度不足。");
            }
        }

        //显示账号信息
        public override void DisplayBalance()
        {
            Console.WriteLine($"账户信息: {getAccountNumber}, 余额: {getBalance}, 信用额度: {getCreditLimit}");
        }
    }
}
